package com.bruan.D7_interfacedemo;

import java.util.ArrayList;

public class StudentOperatorImpl2 implements StudentOperator{

    @Override
    public void printAllInfo(ArrayList<Student> students) {
        int count1=0,count2=0;
        System.out.println("=======全班全部信息如下========");
        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            System.out.println("姓名："+s.getName()+"， 性别"+s.getSex()+" ,分数："+s.getScore());
            if (s.getSex()=='男'){
                count1 ++;
            }else {
                count2++;
            }
        }
        System.out.println("男生人数："+count1+" 女生人数："+count2+" 总人数"+students.size());
        System.out.println("===========================");
    }

    @Override
    public void printAverageScore(ArrayList<Student> students) {
        double allScore = 0;
        double maxScore = students.get(0).getScore();
        double minScore = students.get(0).getScore();
        for (int i = 0; i < students.size(); i++) {
            double currentScore = students.get(i).getScore();
            allScore += currentScore;
            if(currentScore>maxScore){
                maxScore = currentScore;
            }
            if (currentScore<minScore){
                minScore = currentScore;
            }
        }
        System.out.println("最高分"+maxScore+"最低分"+minScore);
        System.out.println("平均分: "+ (allScore-maxScore-minScore) /students.size());
    }
}
